package com.dtcnet.skmvp.network.simpleNet;

import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;

import com.rxjava.rxlife.Scope;
import com.dtcnet.skmvp.network.simpleNet.owner.SkOwnerObservableSet;
import com.dtcnet.skmvp.network.simpleNet.owner.SkOwnerSimpleConverter;
import com.dtcnet.skmvp.network.simpleNet.scope.SkScopeObservableSet;
import com.dtcnet.skmvp.network.simpleNet.scope.SkScopeSimpleConverter;

import io.reactivex.rxjava3.core.Observable;

public final class SkLife {
    public static <T> SkOwnerSimpleConverter<T> asSimple(LifecycleOwner owner) {
        return new SkOwnerSimpleConverter<T>() {
            @Override
            public SkOwnerObservableSet<T> apply(Observable<T> upstream) {
                return new SkOwnerObservableSet<T>(upstream, owner);
            }
        };
    }

    public static <T> SkScopeSimpleConverter<T> asSimple(Scope scope) {
        return new SkScopeSimpleConverter<T>() {
            @NonNull
            @Override
            public SkScopeObservableSet<T> apply(@NonNull Observable<T> upstream) {
                return new SkScopeObservableSet<T>(upstream, scope);
            }
        };
    }
}
